package com.zhx.taoda;


import com.zhx.taoda.model.TemplateField;
import com.zhx.taoda.utils.ExcelUtils;
import com.zhx.taoda.utils.FileUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;


public class Main {
    private static final Logger log = Logger.getLogger("Main");
    /**
     * 创建文件输出目录
     */
    private static final String PDF_PATH = "C:\\Users\\PC\\Downloads\\";
    /**
     * 模板文件
     */
    private static final String TEMPLATE_PDF_PATH = "C:\\Users\\PC\\Desktop\\growing\\taoda\\src\\main\\resources\\申请人声明.pdf";

    // private static final String DATA_FILE_PATH = "../data.txt";

    private static final String EXCEL_DATA_FILE_PATH = "C:\\Users\\PC\\Desktop\\growing\\taoda\\src\\main\\resources\\data.xls";


    public static void main(String[] args) {
        log.info("start");
        FileUtils.mkdir(PDF_PATH);
        List<List<String>> excelList = ExcelUtils.getExcelData(EXCEL_DATA_FILE_PATH);
        List<TemplateField> list = ConvertService.buildTemplateField(excelList);
        for (TemplateField field : list) {
            String pdfFile = PDF_PATH + field.getPreLoanNo() + "_" + field.getCustomerName() + ".pdf";
            ConvertService.createEmptyPdf(pdfFile);
            Map<String, Object> fieldMap = new HashMap<>();
            fieldMap.put("preLoanNo", field.getPreLoanNo());
            fieldMap.put("customerName", field.getCustomerName());
            fieldMap.put("idCard", field.getIdCard());
            fieldMap.put("submitTime", field.getSubmitTime());
            ConvertService.convertPdf(TEMPLATE_PDF_PATH, pdfFile, fieldMap);
        }

        // 1: 参数 templatePath, convertData: 示例
        // 2：JsonArrays
        // 3: 解析出 pdfPath，调用 createEmptyPdf 创建空pdf文件
        // 4：取出params, 设置如form生成pdf

    }
}
